<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Cache\Driver\Redis;
require_once '/workerman/GatewayClient/Gateway.php';
use GatewayClient\Gateway;
/*
 * web登录控制器
 *@auth suo
 *Time 2017-08-11
 */
class LoginController extends Controller {
  
//public function __construct() {
//		parent::__construct();
//		$this->$qrcode;
//	}
  
	public function index(){
		if(session('adminUser')){//已经登录跳转到后台首页
			$this->redirect('/admin');
		}
		$this->display();
    }



//	web手动登录
	public function check(){
		$username = I('username');
		$password = I('password');
		if(!trim($username)){
		 return	show(0,"用户名不能为空");
		}
		
		if(!trim($password)){
		 return	show(0,"密码不能为空");
		}
		
        //	校验ok  	数据操作
		$ret = D('Admin')->getAdminByUsername($username);
		if(!$ret){
				return show(0,'用户不存在');
		}
		if($ret['password']!=getMd5Password($password)){
			return show(0,'密码不正确');
		}
		session('adminUser',$ret);

		return show(1, '登录成功！');
	}
	
	public function loging ($ret){
		session('adminUser',$ret);
		$this->display('index');
	}
	
	public function pushlogin (){
		$username = I('username');
		$password = I('password');
		if(!trim($username)){
		 return	show(0,"用户名不能为空");
		}
		
		if(!trim($password)){
		 return	show(0,"密码不能为空");
		}
		
//	校验ok  	数据操作
		$ret = D('Admin')->getAdminByUsername($username);
		if(!$ret){
				return show(0,'用户不存在');
		}
		if($ret['password']!=getMd5Password($password)){
			return show(0,'密码不正确');
		}
		session('adminUser',$ret);
		$this->redirect('/admin');
	}
	
	
	public function loginout (){
		session('adminUser',null);
		$this->redirect('/admin/login');
	}
}